#include "myapp.h"
#include "pt_dialog.h"

DECLARE_APP(MyApp);

BEGIN_EVENT_TABLE(Input_PTranDialog, wxDialog)
	EVT_BUTTON(input_ptran_ok,Input_PTranDialog::ipt_OkBtn_clicked)
	EVT_BUTTON(input_ptran_can,Input_PTranDialog::ipt_CanBtn_clicked)
	EVT_BUTTON(input_ptran_baseinfo,Input_PTranDialog::ipt_InputBaseInfo_clicked)
	EVT_CHOICE(input_ptran_periotiming,Input_PTranDialog::ipt_PeriodicalTiming_selected)
END_EVENT_TABLE() 
BEGIN_EVENT_TABLE(PeriodicalTranDialog, wxDialog)
	EVT_BUTTON(periodicaltran_ok,PeriodicalTranDialog::pt_OkBtn_clicked)
	EVT_BUTTON(periodicaltran_can,PeriodicalTranDialog::pt_CanBtn_clicked)
	EVT_BUTTON(periodicaltran_add,PeriodicalTranDialog::pt_AddPeriodic_clicked)
	EVT_BUTTON(periodicaltran_mod,PeriodicalTranDialog::pt_ModPeriodic_clicked)
	EVT_BUTTON(periodicaltran_del,PeriodicalTranDialog::pt_DelPeriodic_clicked)
	EVT_LIST_ITEM_SELECTED(periodicaltran_periolist,PeriodicalTranDialog::pt_PeriodicalList_selected)
END_EVENT_TABLE() 

//***************************************************************************************************
//  PeriodicalTranDialog
//---------------------------------------------------------------
// PeriodicalTranDialog constructor
//---------------------------------------------------------------
PeriodicalTranDialog::PeriodicalTranDialog(wxWindow *parent)
:wxDialog(parent, wxID_ANY, _("Setting of Periodical transaction"), wxDefaultPosition, wxDefaultSize)
{
	SetClientSize(wxSize(640,480));

	pt_mainPanel = new wxPanel(this,wxID_ANY);
	pt_PeriodicalList = new wxListCtrl(pt_mainPanel, periodicaltran_periolist, wxPoint(-1,-1),wxSize(-1,-1),wxLC_REPORT|wxLC_SINGLE_SEL);
	wxListItem itemcol;
	itemcol.SetText(_("Timing"));
	pt_PeriodicalList->InsertColumn(0,itemcol);
	pt_PeriodicalList->SetColumnWidth(0, 120);
	itemcol.SetText(_("Handling"));
	pt_PeriodicalList->InsertColumn(1,itemcol);
	pt_PeriodicalList->SetColumnWidth(1, 100);
	itemcol.SetText(_("Expense"));
	pt_PeriodicalList->InsertColumn(2,itemcol);
	pt_PeriodicalList->SetColumnWidth(2, 100);
	itemcol.SetText(_("Value"));
	pt_PeriodicalList->InsertColumn(3,itemcol);
	pt_PeriodicalList->SetColumnWidth(3, 85);
	itemcol.SetText(_("Memo"));
	pt_PeriodicalList->InsertColumn(4,itemcol);
	pt_PeriodicalList->SetColumnWidth(4, 100);

	pt_AddPeriodic = new wxButton(pt_mainPanel, periodicaltran_add, _("Add"), wxPoint(-1,-1),wxSize(80,-1));
	pt_ModPeriodic = new wxButton(pt_mainPanel, periodicaltran_mod, _("Modify"), wxPoint(-1,-1),wxSize(80,-1));
	pt_DelPeriodic = new wxButton(pt_mainPanel, periodicaltran_del, _("Remove"), wxPoint(-1,-1),wxSize(80,-1));

	wxBoxSizer *mbsizer1 = new wxBoxSizer(wxVERTICAL);
		wxBoxSizer *mbsizer2 = new wxBoxSizer(wxHORIZONTAL);
		mbsizer2->Add(pt_PeriodicalList,1,wxTOP|wxLEFT|wxEXPAND,0);
			wxBoxSizer *mbsizer3 = new wxBoxSizer(wxVERTICAL);
			mbsizer3->Add(pt_AddPeriodic,0,wxTOP|wxLEFT,0);
			mbsizer3->Add(pt_ModPeriodic,0,wxTOP|wxLEFT,0);
			mbsizer3->Add(pt_DelPeriodic,0,wxTOP|wxLEFT,0);
		mbsizer2->Add(mbsizer3,0,wxTOP|wxLEFT,0);
	mbsizer1->Add(mbsizer2,1,wxTOP|wxLEFT|wxEXPAND,5);

	pt_mainPanel->SetSizer(mbsizer1);
	pt_mainPanel->Layout();

	ipt_dialog = new Input_PTranDialog(this);
	pt_OkBtn = new wxButton(this, periodicaltran_ok, _T("OK"), wxPoint(-1,-1),wxSize(85,-1));
	pt_CanBtn = new wxButton(this, periodicaltran_can, _("Cancel"), wxPoint(-1,-1),wxSize(85,-1));
	
	wxBoxSizer *bsizer1 = new wxBoxSizer(wxVERTICAL);
		wxBoxSizer *bsizer2 = new wxBoxSizer(wxHORIZONTAL);
		bsizer2->Add(pt_OkBtn,0,wxTOP|wxLEFT,0);
		bsizer2->Add(pt_CanBtn,0,wxLEFT,5);
	bsizer1->Add(pt_mainPanel,1,wxBOTTOM|wxEXPAND,5);
	bsizer1->Add(bsizer2,0,wxBOTTOM|wxRIGHT|wxALIGN_RIGHT,10);
	this->SetSizer(bsizer1);
	this->Layout();
	listselect = -1;
}
//---------------------------------------------------------------
// ok button event
//---------------------------------------------------------------
void PeriodicalTranDialog::pt_OkBtn_clicked(wxCommandEvent &event)
{
	this->EndModal(periodicaltran_ok);
	this->Hide();
}
//---------------------------------------------------------------
// cancel button event
//---------------------------------------------------------------
void PeriodicalTranDialog::pt_CanBtn_clicked(wxCommandEvent &event)
{
	this->EndModal(periodicaltran_can);
	this->Hide();
}
//---------------------------------------------------------------
// pt_AddPeriodic button event
//---------------------------------------------------------------
void PeriodicalTranDialog::pt_AddPeriodic_clicked(wxCommandEvent &event)
{
	ipt_dialog->ClearControl();
	ipt_dialog->CenterOnParent();
	if (ipt_dialog->ShowModal() == input_ptran_ok) {
		DB_periodical newrow = ipt_dialog->GetData_Periodical();
		newrow.SetFlag(add_mt);
		dbperiod.Add(newrow);
		//for Control
		wxString arr[5];
		//---set timing
		if (newrow.GetTiming() < 2) {
			arr[0] = GetTimingString(newrow.GetTiming()) +
				StrF(_T(": %d %s"),newrow.GetTimingDay(),_("-th day"));
		}else{
			arr[0] = GetTimingString(newrow.GetTiming());
		}
		//---set account
		arr[1] = wxGetApp().AppDB.GetAccount(newrow.GetBudget().GetHandling()).GetName();
		//---set expense and item of expense
		wxString sql = StrF(WXSQL_GET_EXPENSE_AND_ITEM,
			newrow.GetBudget().GetExpense(),newrow.GetBudget().GetItems());
		wxSQLite3ResultSet rset = wxGetApp().SQLDB().ExecuteQuery(sql);
		while (rset.NextRow()) {
			arr[2] = rset.GetString(0) + _T(", ") +
				rset.GetString(1);
		}
		//---set income or expenditure
		if (newrow.GetBudget().GetIncome() > 0) {
			arr[3] = IntToStr(newrow.GetBudget().GetIncome());
		}else if (newrow.GetBudget().GetExpenditure() > 0) {
			arr[3] = IntToStr(newrow.GetBudget().GetExpenditure());
		}else{
			arr[3] = _T("0");
		}
		//---set memo
		arr[4] = newrow.GetBudget().GetMemo();

		InsertRow(pt_PeriodicalList,arr,5);

	}
}
//---------------------------------------------------------------
// pt_ModPeriodic button event
//---------------------------------------------------------------
void PeriodicalTranDialog::pt_ModPeriodic_clicked(wxCommandEvent &event)
{
	if (dbperiod.GetCount() == 0) {
		wxMessageBox(_("Periodical transaction not found."),APPTITLE,wxOK|wxICON_EXCLAMATION,this);
		return;
	}
	ipt_dialog->BindData_Periodical(dbperiod.Item(listselect));
	ipt_dialog->CenterOnParent();
	if (ipt_dialog->ShowModal() == input_ptran_ok) {
		dbperiod.Item(listselect) = ipt_dialog->GetData_Periodical();
		dbperiod.Item(listselect).SetFlag(mod_mt);
		//for Control
		wxString arr[5];
		//---set timing
		if (dbperiod.Item(listselect).GetTiming() < 2) {
			arr[0] = GetTimingString(dbperiod.Item(listselect).GetTiming()) +
				StrF(_T(": %d %s"),dbperiod.Item(listselect).GetTimingDay(),_("-th day"));
		}else{
			arr[0] = GetTimingString(dbperiod.Item(listselect).GetTiming());
		}
		//---set account
		arr[1] = wxGetApp().AppDB.GetAccount(dbperiod.Item(listselect).GetBudget().GetHandling()).GetName();
		//---set expense and item of expense
		wxString sql = StrF(_T("select ex_name, it_name from db_expense, db_items where ex_id = %d and it_id = %d and ex_id = it_expense;"),
			dbperiod.Item(listselect).GetBudget().GetExpense(),dbperiod.Item(listselect).GetBudget().GetItems());
		wxSQLite3ResultSet rset = wxGetApp().SQLDB().ExecuteQuery(sql);
		while (rset.NextRow()) {
			arr[2] = rset.GetString(0) + _T(", ") +
				rset.GetString(1);
		}
		//---set income or expenditure
		if (dbperiod.Item(listselect).GetBudget().GetIncome() > 0) {
			arr[3] = IntToStr(dbperiod.Item(listselect).GetBudget().GetIncome());
		}else if (dbperiod.Item(listselect).GetBudget().GetExpenditure() > 0) {
			arr[3] = IntToStr(dbperiod.Item(listselect).GetBudget().GetExpenditure());
		}else{
			arr[3] = _T("0");
		}
		//---set memo
		arr[4] = dbperiod.Item(listselect).GetBudget().GetMemo();

		ChangeRow(pt_PeriodicalList,listselect,arr,5);
	}

}
void PeriodicalTranDialog::pt_DelPeriodic_clicked(wxCommandEvent &event)
{
	if (dbperiod.GetCount() == 0) {
		wxMessageBox(_("Periodical transaction not found."),APPTITLE,wxOK|wxICON_EXCLAMATION,this);
		return;
	}
	//for DB
	dbperiod.Item(listselect).SetFlag(del_mt);

	DeleteRow(pt_PeriodicalList,listselect);
}
void PeriodicalTranDialog::pt_PeriodicalList_selected(wxListEvent &event)
{
	listselect = event.GetIndex();
}

//---------------------------------------------------------------
// insert row in wxListCtrl
//---------------------------------------------------------------
void PeriodicalTranDialog::InsertRow(wxListCtrl *lstcrtl, wxString list[], size_t size)
{
	int index = (lstcrtl->GetItemCount() == 0) ? 0 : lstcrtl->GetItemCount();
	
	long tmp = lstcrtl->InsertItem(index,list[0]);
	wxListItem item;
	item.SetId(tmp);
	for (int i = 1; i < (int)size; i++) {
		item.SetColumn(i);
		item.SetText(list[i]);
		lstcrtl->SetItem(item);
	}
	
}
//---------------------------------------------------------------
// change row in wxListCtrl
//---------------------------------------------------------------
void PeriodicalTranDialog::ChangeRow(wxListCtrl *lstcrtl, int index, wxString list[], size_t size)
{
	wxListItem item;
	item.SetId(index);
	for (int i = 0; i < (int)size; i++) {
		item.SetColumn(i);
		item.SetText(list[i]);
		lstcrtl->SetItem(item);
	}
}
//---------------------------------------------------------------
// delete row in wxListCtrl
//---------------------------------------------------------------
void PeriodicalTranDialog::DeleteRow(wxListCtrl *lstcrtl, int index)
{
	lstcrtl->DeleteItem(index);
}
//---------------------------------------------------------------
// get timing meaning as string
//---------------------------------------------------------------
wxString PeriodicalTranDialog::GetTimingString(int index)
{
	wxString timing_items[3] = {
		_("Indicated ordered day of week"),_("Indicated ordered day of month"),
		_("last day of month")
	};
	if ((index >= 0) || (index <= 2)) {
		return timing_items[index];
	}
	return wxEmptyString;
}
//---------------------------------------------------------------
// bind window data and DB data
//---------------------------------------------------------------
void PeriodicalTranDialog::BindData_Periodical(DBL_periodical &db)
{
	wxString timing_items[] = {
		_("Indicated ordered day of week"),_("Indicated ordered day of month"),
		_("last day of month")
	};
	dbperiod = db;
	//insert DB data in listctrl
	pt_PeriodicalList->DeleteAllItems();
	for (int i = 0; i < (int)dbperiod.GetCount(); i++) {
		if (dbperiod.Item(i).GetTiming() == 3) continue;
		wxString arr[5];
		//---set timing
		if (dbperiod.Item(i).GetTiming() < 2) {
			arr[0] = GetTimingString(dbperiod.Item(i).GetTiming()) +
				StrF(_T(": %d %s"),dbperiod.Item(i).GetTimingDay(),_("-th day"));
		}else{
			arr[0] = timing_items[dbperiod.Item(i).GetTiming()];
		}
		//---set account
		arr[1] = wxGetApp().AppDB.GetAccount(dbperiod.Item(i).GetBudget().GetHandling()).GetName();
		//---set expense and item of expense
		wxString sql = StrF(_T("select ex_name, it_name from db_expense, db_items where ex_id = %d and it_id = %d and ex_id = it_expense;"),
			dbperiod.Item(i).GetBudget().GetExpense(),dbperiod.Item(i).GetBudget().GetItems());
		wxSQLite3ResultSet rset = wxGetApp().SQLDB().ExecuteQuery(sql);
		while (rset.NextRow()) {
			arr[2] = rset.GetString(0) + _T(", ") +
				rset.GetString(1);
		}
		//---set income or expenditure
		if (dbperiod.Item(i).GetBudget().GetIncome() > 0) {
			arr[3] = IntToStr(dbperiod.Item(i).GetBudget().GetIncome());
		}else if (dbperiod.Item(i).GetBudget().GetExpenditure() > 0) {
			arr[3] = IntToStr(dbperiod.Item(i).GetBudget().GetExpenditure());
		}else{
			arr[3] = _T("0");
		}
		//---set memo
		arr[4] = dbperiod.Item(i).GetBudget().GetMemo();
		InsertRow(pt_PeriodicalList,arr,5);
	}
}
//---------------------------------------------------------------
// get window data as DB data
//---------------------------------------------------------------
DBL_periodical &PeriodicalTranDialog::GetData_Periodical(void)
{
	return dbperiod;
}
//***************************************************************************************************
//  Input_PTranDialog
//---------------------------------------------------------------
// Input_PTranDialog constructor
//---------------------------------------------------------------
Input_PTranDialog::Input_PTranDialog(wxWindow *parent)
:wxDialog(parent, wxID_ANY, _("Input Periodical transaction"), wxDefaultPosition, wxDefaultSize)
{
#ifdef __WXMSW__
	SetClientSize(wxSize(500,375));
#else
	SetClientSize(wxSize(500,380));
#endif

	ipt_mainPanel = new wxPanel(this,wxID_ANY);

	wxString timing_items[] = {
		_("Indicated ordered day of week"),_("Indicated ordered day of month"),
		_("last day of month")
	};
	wxString holiday_items[] = {
		_("no action"),_("work day of before"),_("work day of after")
	};

	wxStaticBox *sbox = new wxStaticBox(ipt_mainPanel,wxID_ANY,_("Input base transaction"));
	wxStaticBoxSizer *sbsizer = new wxStaticBoxSizer(sbox,wxHORIZONTAL);
	ipt_InputedBaseInfoLabel = new wxStaticText(ipt_mainPanel,wxID_ANY,_T(""),wxDefaultPosition,wxSize(320,100),wxST_NO_AUTORESIZE);
	ipt_InputBaseInfo = new wxButton(ipt_mainPanel, input_ptran_baseinfo, _("Input base"), wxPoint(-1,-1),wxSize(120,-1));
	sbsizer->Add(ipt_InputedBaseInfoLabel,5,wxTOP|wxLEFT);
	sbsizer->Add(ipt_InputBaseInfo,0,wxTOP|wxLEFT);
	ipt_SetAfterInputValue = new wxCheckBox(ipt_mainPanel,wxID_ANY, _("the day will come, open dialog to input value."));
	ipt_SetAfterInputMemo = new wxCheckBox(ipt_mainPanel,wxID_ANY, _("the day will come, open dialog to input memo."));
	ipt_PeriodicalTiming = new wxChoice(ipt_mainPanel,input_ptran_periotiming,wxDefaultPosition,wxSize(100,-1),3,timing_items);
	ipt_PeriodicalTiming->SetSelection(0);
	wxStaticText *label1 = new wxStaticText(ipt_mainPanel,wxID_ANY,_("-th day"));
	ipt_TimingDay = new wxSpinCtrl(ipt_mainPanel, wxID_ANY, _T("1"),wxDefaultPosition,wxSize(65,-1),wxSP_ARROW_KEYS,1,7,1);
	ipt_CaseHolidayTiming = new wxRadioBox(ipt_mainPanel,wxID_ANY,_("Case of holiday"),wxDefaultPosition,wxDefaultSize,3,holiday_items,3,wxRA_SPECIFY_ROWS);

	wxBoxSizer *mbsizer1 = new wxBoxSizer(wxVERTICAL);
	mbsizer1->Add(sbsizer,0,wxTOP|wxLEFT,0);
	mbsizer1->AddSpacer(5);
	mbsizer1->Add(ipt_SetAfterInputValue,0,wxTOP|wxLEFT,0);
	mbsizer1->Add(ipt_SetAfterInputMemo,0,wxTOP,5);
	mbsizer1->AddSpacer(5);
		wxBoxSizer *mbsizer4 = new wxBoxSizer(wxHORIZONTAL);
		mbsizer4->Add(ipt_PeriodicalTiming,0,wxTOP|wxLEFT,0);
		mbsizer4->Add(ipt_TimingDay,0,wxLEFT,5);
		mbsizer4->Add(label1,0,wxTOP|wxLEFT,3);
	mbsizer1->Add(mbsizer4,0,wxTOP,5);
		//wxBoxSizer *mbsizer2 = new wxBoxSizer(wxHORIZONTAL);
		//	wxBoxSizer *mbsizer3 = new wxBoxSizer(wxVERTICAL);
		//mbsizer2->Add(mbsizer3,0,wxLEFT,5);
	mbsizer1->AddSpacer(5);
	mbsizer1->Add(ipt_CaseHolidayTiming,0,wxLEFT,5);
	//mbsizer1->Add(mbsizer2,0,wxTOP|wxLEFT,5);

	ipt_mainPanel->SetSizer(mbsizer1);
	ipt_mainPanel->Layout();

	ipt_OkBtn = new wxButton(this, input_ptran_ok, _T("OK"), wxPoint(-1,-1),wxSize(85,-1));
	ipt_CanBtn = new wxButton(this, input_ptran_can, _("Cancel"), wxPoint(-1,-1),wxSize(85,-1));
	
	de_dialog = new DetailEditor(this);
	wxBoxSizer *bsizer1 = new wxBoxSizer(wxVERTICAL);
		wxBoxSizer *bsizer2 = new wxBoxSizer(wxHORIZONTAL);
		bsizer2->Add(ipt_OkBtn,0,wxTOP|wxLEFT,0);
		bsizer2->Add(ipt_CanBtn,0,wxLEFT,5);
	bsizer1->Add(ipt_mainPanel,0,wxBOTTOM,5);
	bsizer1->Add(bsizer2,0,wxRIGHT|wxALIGN_RIGHT,10);
	this->SetSizer(bsizer1);
	this->Layout();
	isinputbase = false;
}
//---------------------------------------------------------------
// ok button event
//---------------------------------------------------------------
void Input_PTranDialog::ipt_OkBtn_clicked(wxCommandEvent &event)
{
	this->EndModal(input_ptran_ok);
	this->Hide();
}
//---------------------------------------------------------------
// cancel button event
//---------------------------------------------------------------
void Input_PTranDialog::ipt_CanBtn_clicked(wxCommandEvent &event)
{
	this->EndModal(input_ptran_can);
	this->Hide();
}
//---------------------------------------------------------------
// pt_InputBaseInfo button event
//---------------------------------------------------------------
void Input_PTranDialog::ipt_InputBaseInfo_clicked(wxCommandEvent &event)
{
	de_dialog->bindData_InputDate(wxDateTime::UNow());
	//if (isinputbase) {
		de_dialog->SetAccount(-1);
		de_dialog->bindData_ExistData(tmpdbday);
	/*}else{
		de_dialog->SetExpense(in_it);
		de_dialog->SetItems(0);
		de_dialog->SetAccount(-1);
		de_dialog->ChangeEnable(-1,true);
		de_dialog->ClearControl();
	}*/
	isinputbase = false;
	de_dialog->CenterOnParent();
	if (de_dialog->ShowModal() == detaile_ok) {
		isinputbase = true;

		tmpdbday.SetDate(de_dialog->GetDataDate());
		tmpdbday.SetId(-1);
		tmpdbday.SetIO((InoutType)de_dialog->GetDataIncome());
		tmpdbday.SetExpense(de_dialog->GetDataExpense());
		tmpdbday.SetItems(de_dialog->GetDataItems());
		tmpdbday.SetHandling(de_dialog->GetDataHandling());
		if (de_dialog->GetDataIncome() == 0) {
			tmpdbday.SetIncome(de_dialog->GetDataValue());
			tmpdbday.SetExpenditure(0);
		}else{
			tmpdbday.SetIncome(0);
			tmpdbday.SetExpenditure(de_dialog->GetDataValue());
		}
		tmpdbday.SetMemo(de_dialog->GetDataMemo());
		wxString label;
		if (tmpdbday.GetIO() == in_it) {
			label.Append(StrF(_("Income: %d\n"),de_dialog->GetDataValue()));
		}else if (tmpdbday.GetIO() == out_it) {
			label.Append(StrF(_("Expenditure: %d\n"),de_dialog->GetDataValue()));
		}
		label.Append(StrF(_T("%s(%s)\n"),de_dialog->GetDataExpenseString().c_str(),de_dialog->GetDataItemsString().c_str()));
		label.Append(StrF(_T("%s\n"),de_dialog->GetDataHandlingString().c_str()));
		label.Append(tmpdbday.GetMemo());
		ipt_InputedBaseInfoLabel->SetLabel(label);
		//dbperiod.SetBudget(db);
	}
}
void Input_PTranDialog::ipt_PeriodicalTiming_selected(wxCommandEvent &event)
{
	switch (ipt_PeriodicalTiming->GetSelection()) {
	//Indicated ordered day of week
	case 0:
		ipt_TimingDay->Enable(true);
		ipt_TimingDay->SetRange(1,7);
		break;
	//Indicated ordered day of month
	case 1:
		ipt_TimingDay->Enable(true);
		ipt_TimingDay->SetRange(1,31);
		break;
	//last day of month
	default:
		ipt_TimingDay->Enable(false);
		break;
	}
}
//---------------------------------------------------------------
// bind window data and DB data
//---------------------------------------------------------------
void Input_PTranDialog::BindData_Periodical(DB_periodical &db)
{
	dbperiod = db;
	DB_day tmpdbday = dbperiod.GetBudget();
	wxString label;
	DB_expense expense = wxGetApp().AppDB.GetExpense(tmpdbday.GetExpense(),tmpdbday.GetIO());
	DB_items items = wxGetApp().AppDB.GetItems(tmpdbday.GetItems(),tmpdbday.GetExpense());
	DB_account hand = wxGetApp().AppDB.GetAccount(tmpdbday.GetHandling());
	if (tmpdbday.GetIO() == in_it) {
		label.Append(StrF(_("Income: %d\n"),tmpdbday.GetIncome()));
	}else if (tmpdbday.GetIO() == out_it) {
		label.Append(StrF(_("Expenditure: %d\n"),tmpdbday.GetExpenditure()));
	}
	label.Append(StrF(_T("%s(%s)\n"),expense.GetName().c_str(),items.GetName().c_str()));
	label.Append(StrF(_T("%s\n"),hand.GetName().c_str()));
	label.Append(tmpdbday.GetMemo());
	ipt_InputedBaseInfoLabel->SetLabel(label);

	ipt_PeriodicalTiming->SetSelection(dbperiod.GetTiming());
	wxCommandEvent evt;
	ipt_PeriodicalTiming_selected(evt);
	ipt_TimingDay->SetValue(dbperiod.GetTimingDay());
	ipt_SetAfterInputValue->SetValue(dbperiod.GetInputValue());
	ipt_SetAfterInputMemo->SetValue(dbperiod.GetInputMemo());
	ipt_CaseHolidayTiming->SetSelection(dbperiod.GetHoliday());

	ipt_PeriodicalTiming_selected(evt);
}
//---------------------------------------------------------------
// get window data as DB data
//---------------------------------------------------------------
DB_periodical &Input_PTranDialog::GetData_Periodical(void)
{
	dbperiod.SetTiming(ipt_PeriodicalTiming->GetSelection());
	dbperiod.SetTimingDay(ipt_TimingDay->GetValue());
	dbperiod.SetInputValue(ipt_SetAfterInputValue->GetValue());
	dbperiod.SetInputMemo(ipt_SetAfterInputMemo->GetValue());
	dbperiod.SetHoliday(ipt_CaseHolidayTiming->GetSelection());

	//DB_day db;
	//for DB
	dbperiod.SetFlag(add_mt);
	dbperiod.SetDate(wxDateTime::Now());
	dbperiod.SetInputValue(ipt_SetAfterInputValue->GetValue());
	dbperiod.SetInputMemo(ipt_SetAfterInputMemo->GetValue());
	dbperiod.SetTiming(ipt_PeriodicalTiming->GetSelection());
	dbperiod.SetTimingDay(ipt_TimingDay->GetValue());
	dbperiod.SetHoliday(ipt_CaseHolidayTiming->GetSelection());
	/*db.SetDate(de_dialog->GetDataDate());
	db.SetId(-1);
	db.SetIO((InoutType)de_dialog->GetDataIncome());
	db.SetExpense(de_dialog->GetDataExpense());
	db.SetItems(de_dialog->GetDataItems());
	db.SetHandling(de_dialog->GetDataHandling());
	if (de_dialog->GetDataIncome() == 0) {
		db.SetIncome(de_dialog->GetDataValue());
		db.SetExpenditure(0);
	}else{
		db.SetIncome(0);
		db.SetExpenditure(de_dialog->GetDataValue());
	}
	db.SetMemo(de_dialog->GetDataMemo());*/
	dbperiod.SetBudget(tmpdbday);
	isinputbase = false;

	return dbperiod;
}
void Input_PTranDialog::ClearControl(void)
{
	ipt_SetAfterInputValue->SetValue(false);
	ipt_SetAfterInputMemo->SetValue(false);
	ipt_PeriodicalTiming->SetSelection(0);
	ipt_TimingDay->SetValue(0);
	ipt_CaseHolidayTiming->SetSelection(0);
}
